package org.onvivals.app.ai.llm;

import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject;
import org.onvivals.app.ai.llm.model.coze.CozeCloudService;
import org.onvivals.app.ai.llm.model.deepseek.DeepseekCloudService;
import org.onvivals.app.ai.llm.model.doubao.DoubaoCloudService;
import org.onvivals.app.ai.llm.model.minimax.MinimaxCloudService;
import org.onvivals.app.ai.llm.model.moonshot.MoonshotCloudService;
import org.onvivals.app.ai.llm.model.openAI.OpenAICloudService;
import org.onvivals.app.ai.llm.model.qwen.QwenCloudService;
import org.onvivals.app.ai.llm.model.xh.XhCloudService;
import org.onvivals.common.constant.Constant;
import org.onvivals.module.pms.entity.PmsLlmConfig;
import org.onvivals.module.pms.entity.PmsRole;
import org.onvivals.module.pms.service.IPmsLlmConfigService;

/**
 * LLMFactory
 *
 * @author weirdor (179946422@qq.com)
 * @version v1.0.0
 */
public class LLMFactory {

	private static IPmsLlmConfigService llmConfigService;

	static {
		LLMFactory.llmConfigService = SpringUtil.getBean(IPmsLlmConfigService.class);
	}

	public static AbstractLlmService build(PmsRole roles) {
		//todo 异常
		PmsLlmConfig pmsLlmConfig = llmConfigService.getById(roles.getLlmId());
		JSONObject llmConfig = pmsLlmConfig.getLlmConfig();
		String llmType = pmsLlmConfig.getLlmType();
		if (llmType.equals(Constant.llmService.COUZE.getValue())) {
			return new CozeCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.MOONSHOT.getValue())) {
			return new MoonshotCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.DEEPSEEK.getValue())) {
			return new DeepseekCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.XH.getValue())) {
			return new XhCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.MINIMAX.getValue())) {
			return new MinimaxCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.QWEN.getValue())) {
			return new QwenCloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.OPENAI.getValue())) {
			return new OpenAICloudService(llmConfig, roles);
		}
		if (llmType.equals(Constant.llmService.DOUBAO.getValue())) {
			return new DoubaoCloudService(llmConfig, roles);
		}
		return null;
	}
}
